﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Configuration;
using System.Xml.Linq;

namespace SPlusres.Business
{
    public class SystemSetting
    {
        private static string _conectionstring = null;

        /// <summary>
        /// Connection String Property
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                if (_conectionstring == null)
                    _conectionstring = Key("ConnectionString");

                return _conectionstring;
            }
        }

        private static string _encryptkey = null;

        /// <summary>
        /// EncryptKey
        /// </summary>
        public static string EncryptKey
        {
            get
            {
                if (_encryptkey == null)
                    _encryptkey = Key("EncryptKey");

                return _encryptkey;
            }
        }

        /// <summary>
        /// System Value
        /// </summary>
        private static string Key(string key)
        {
            try
            {
                var element = XElement.Load(System.Web.HttpContext.Current.Server.MapPath("~/Config/Setting.xml")).Elements("add").Where(m => m.Attribute("name").Value == key).FirstOrDefault();

                if (element != null)
                    return element.Attribute("value").Value;

                return null;
            }
            catch (Exception ex)
            {
                SystemLog.WriteLog(ex);

                return null;
            }
        }
    }
}
